package com.matchmealpha;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;

public class WallPostDialogListener implements
		com.facebook.android.Facebook.DialogListener {

	private Context context;
	private int postId;

	public WallPostDialogListener(Context context, int postId) {
		this.context = context;
		this.postId = postId;
	}

	/**
	 * Called when the dialog has completed successfully
	 */
	public void onComplete(Bundle values) {
		if (values.isEmpty()) {
			return;
		}

		if (!values.containsKey("post_id")) {
			try {
				/*
				Bundle parameters = new Bundle();
				parameters.putString("message", "MatchMe - test2!");
				MatchMeTabWidget.mFacebook.dialog(this.context,
						"stream.publish", parameters, this);
				*/
			//	byte[] barray = MatchMeTabWidget.intArrayToByte(this.picInt);
				
				Bundle params = new Bundle();
				/*params.putString("method", "photos.upload");
				params.putByteArray("picture", (byte[])"http://www.jaunted.com/files/3873/panda.jpg".getBytes() );
				//params.putByteArray("message", "Test".getBytes());
				//params.putByteArray("name", "PPPPPPP".getBytes());
				//params.putByteArray("link", "http://bit.ly/12345".getBytes());
				//params.putByteArray("description", "bad panda!".getBytes());
				//params.putByteArray("picture", barray );
				params.putString(Facebook.TOKEN, params.getString(Facebook.TOKEN));
				
				
				//params.putString("picture", "http://www.jaunted.com/files/3873/panda.jpg");
				//params.putByteArray("picture", barray );
				//String response = MatchMeTabWidget.mFacebook.request("me/photos",params,"POST");
				MatchMeTabWidget.mAsyncRunner.request(null, params, "POST", new WallPostRequestListener(),null);*/
				
				params.putString("link", MatchMeTabWidget.IMAGE_URL + "/" + postId);
				
				MatchMeTabWidget.mAsyncRunner.request("me/feed", params, "POST", new WallPostRequestListener(),null);
				
				Log.d("DialogListener-----", "POSTED!!!!!!!!!!!!!!!!!!!!" );

				
			} catch (Exception e) {
				Log.d("DialogListener-----", "ERROR" + e.getMessage());
			}
		}
	}

	@Override
	public void onCancel() {
		// No special processing if dialog has been canceled
	}

	@Override
	public void onError(DialogError e) {
		// No special processing if dialog has been canceled
	}

	@Override
	public void onFacebookError(FacebookError e) {
		// No special processing if dialog has been canceled
	}
}
